from random import randrange

from model import Select, Insert


#def newPlayer(data):
    #cu.execute("insert into players(id, name, email, passwd, salt, location, description, colors, discipline, circle, race, gender, age, \
    #spouse_name, dexterity, strength, toughness, perception, willpower, charisma, initiative, fly, max_carry, max_lift, physical_defense, \
    #spell_defense, social_defense, normal_armor, mystical_armor, wound_threshold, damage, wound, unconscious_rating, death_rating, \
    #blood_magic_cost, recovery_tests_left, recovery_tests_total, karma_dice, karma_current, karma_max, legend_unspent, legend_total, passion) \
    #values (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", data)


#def createUser(self, session, pname, ppass):
    #self.salty = self.generate_salt()
    #self.truepass = self.encpass(ppass, self.salty)

    ##self.test = (pname, self.email, self.truepass, self.salty, self.ansi)
    #self.data = (pname, self.email, self.truepass, self.salty, 0, self.description, self.ansi, self.discipline, self.circle, \
		 #self.race, self.gender, self.age, self.spouse_name, self.dexterity, self.strength, self.toughness, self.perception, \
		 #self.willpower, self.charisma, self.initiative, self.fly, self.max_carry, self.max_lift, self.physical_defense, \
		 #self.spell_defense, self.social_defense, self.normal_armor, self.mystical_armor, self.wound_threshold, self.damage, \
		 #self.wound, self.unconscious_rating, self.death_rating, self.blood_magic_cost, self.recovery_tests_left, \
		 #self.recovery_tests_total, self.karma_dice, self.karma_current, self.karma_max, self.legend_unspent, self.legend_total, \
		 #self.passion)
    
##("insert into players(id, name, email, passwd, salt, location, description, colors, discipline, circle, race, gender, age, spouse_name, 
##dexterity, strength, toughness, perception, willpower, charisma, initiative, fly, max_carry, max_lift, physical_defense, spell_defense,
##social_defense, normal_armor, mystical_armor, wound_threshold, damage, wound, unconscious_rating, death_rating, blood_magic_cost, 
##recovery_tests_left, recovery_test_total, karma_dice, karma_current, karma_max, legend_unspent, legend_total)\
##values (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", data)    
    
    
    #self.test = (pname, self.email, self.truepass, self.salty, self.ansi)
            #Insert.newPlayer(self.test)
    
    #Insert.newPlayer(self.data)

    #session.push(tpl.NEW_PLAYER + tpl.PRESS_ENTER)



    
# the following must (or can) be input from player
# name, Password, lastname, race, sex, passion, discipline
# Dexterity, Strength, Toughness, Perception, Willpower, Charisma, Decription
#
#the following can be derived or achieved in game
# spousename, age, discipline, circle, karmaCurrent, KarmaMax, KarmaCost, KarmaDice
# PhysicalDefense, SpellDefense, NormalArmor
# MysticalArmor, MaxCarry, MaxLift, Initiative, LegendPointTotal, LegendPointUnspent
# Damage, Wound, UnconsciousRating, RecoveryTest, BloodMagic, WoundThreshold
# DeathRating, RecoveryDice, Money, DateLastOn, PlayingFrequency, IsBot, RoomID, loginID
#

#dbpool = adbapi.ConnectionPool("MySQLdb", "localhost", "root", "Oicu812@2", "earthdawndb")

# name, Password, lastname, race, sex, passion, discipline
# Dexterity, Strength, Toughness, Perception, Willpower, Charisma, Decription

#insertStatement = 'insert into players (name,password,lastname,race,sex,passion,discipline,dexterity,strength,toughness,\
    #perception,willpower,charisma,physicaldefense, spelldefense, socialdefense, maxcarry, \
    #maxlift, deathrating, woundthreshold, unconsciousrating, recoverytest, mysticalarmor, \
    #movementnormal, movementcombat, flyingcombat, flyingnormal, karmadice, karmacost, karmacurrent, karmamax, initiative,   \
    #recoverydice, datelaston, spousename,age,circle, normalarmor, damage, wound, bloodmagic, legendunspent, \
    #legendtotal, legenddevotion, money, playingfrequency, isbot, roomid ,description) values (\''


#   Dexterity: d    Strength: s    Toughness: t    Perception: p    Willpower: w    Charisma:  c

# need to have a unique stats variable to ensure people don't log off then log on real quick to
# circumvent the stat min/max and point allocations

stats = {'d':2, 's':2, 't':2, 'p':2, 'w':2, 'c':2, 'points':72}
pointCost = {'2':3, '3':2, '4':1, '5':0, '6':-1, '7':-2, '8':-3, '9':-4, '10':-5, '11':-6, '12':-8, '13':-10, '14':-13, '15':-16, '16':-19, '17':-21, '18':-23}
race = ''
raceStats = {
    #'obsidiman': {'d':(2,18), 's':(9,18), 't':(2,18), 'p':(2,18), 'w':(2,18), 'c':(2,18)},
    #'troll': {'d':(2,18), 's':(7,18), 't':(9,18), 'p':(2,18), 'w':(2,18), 'c':(2,18)},
    #'windling': {'d':(2,18), 's':(2,15), 't':(2,18), 'p':(2,18), 'w':(2,18), 'c':(2,18)}
    'obsidiman': {'s':(9,18)},
    'troll': {'s':(7,18), 't':(9,18)},
    'windling': {'s':(2,15)}
    }
statMod = {}
    

#def doCreateCharacterName(self):
    #"Create a new character name for the game"
    #if self.cmd:
	#self.user = self.cmd
	#self.insertStatement = self.insertStatement + '%s\',\'' % (string.replace(self.cmd,"'","\\'"))
	#self.setState(self.doCreateCharacterPassword)
    #else:
	#self.sendLine('Please enter a first name for your character')
#doCreateCharacterName.prompt = 'Please enter a FIRST NAME for your character'

#def doCreateCharacterPassword(self):
    #"Create a new character password for the game"
    #if self.cmd:
	#self.insertStatement = self.insertStatement + '%s\',\'' % (string.replace(self.cmd,"'","\\'"))
	#self.setState(self.doCreateCharacterLastName)
    #else:
	#self.sendLine('Please enter a password for your character')
#doCreateCharacterPassword.prompt = 'Please enter a PASSWORD for your character'

#def doCreateCharacterLastName(self):
    #"Create a new character lastname"
    #if self.cmd:
	#self.insertStatement = self.insertStatement + '%s\',\'' % (string.replace(self.cmd,"'","\\'"))
	#self.setState(self.doCreateCharacterRace)
    #else:
	#self.sendLine('Please enter a last name for your character')
#doCreateCharacterLastName.prompt = 'Please enter a LAST NAME for your character'

def doCreateCharacterRace(self, session):
    "Select character race"
    if self.cmd:
	if self.cmd in ["dwarf", "elf", "human", "obsidiman", "ork", "troll", "t\'skrang", "windling"]:
	    #self.insertStatement = self.insertStatement + '%s\',\'' % (string.replace(self.cmd,"'","\\'"))
	    self.race = self.cmd

	    if self.race == 'dwarf':
		self.statMod = {'d':0, 's':2, 't':3, 'p':0, 'w':0, 'c':-1}
	    
	    elif self.race == 'elf':
		self.statMod = {'d':2, 's':0, 't':-2, 'p':1, 'w':1, 'c':1}
		
	    elif self.race == 'human':
		self.statMod = {'d':0, 's':0, 't':0, 'p':0, 'w':0, 'c':0}
	    
	    elif self.race == 'obsidiman':
		self.statMod = {'d':-2, 's':6, 't':4, 'p':-1, 'w':0, 'c':-1}
	    
	    elif self.race == 'ork':
		self.statMod = {'d':-1, 's':3, 't':1, 'p':0, 'w':-1, 'c':-1}
		
	    elif self.race == 'troll':
		self.statMod = {'d':0, 's':4, 't':2, 'p':-1, 'w':1, 'c':0}
	    
	    elif self.race == 't\'skrang':
		self.statMod = {'d':1, 's':0, 't':1, 'p':0, 'w':0, 'c':1}
		
	    elif self.race == 'windling':
		self.statMod = {'d':1, 's':-4, 't':-3, 'p':1, 'w':0, 'c':2} 

	    return True
	    #self.setState(self.doCreateCharacterSex)
	else:
	    session.push('Please enter the RACE for your character\nYour choices are dwarf, elf, human, obsidiman, ork, troll, t\'skrang or windling')
    else:
	session.push('Please enter the RACE for your character\nYour choices are dwarf, elf, human, obsidiman, ork, troll, t\'skrang or windling')
#doCreateCharacterRace.prompt = 'Please enter the RACE for your character\nYour choices are dwarf, elf, human, obsidiman, ork, troll, t\'skrang or windling'

def doCreateCharacterSex(self, session):
    "Create a new character password for the game"
    if self.cmd:
	if self.cmd in ["m", "f", "male", "female"]:
	    if self.cmd in ["m", "f"]:
		self.gender = self.cmd
		#self.insertStatement = self.insertStatement + '%s\',\'' % (self.cmd)
		#self.setState(self.doCreateCharacterPassion)
	    elif self.cmd == "male":
		self.gender = 'm'
		#self.insertStatement = self.insertStatement + 'm\',\''
		#self.setState(self.doCreateCharacterPassion)
	    else:
		self.gender = 'f'
		#self.insertStatement = self.insertStatement + 'f\',\''
		#self.setState(self.doCreateCharacterPassion)
	    return True
	else:
	    session.push('Please enter the gender of your character (m/f)')
    else:
	session.push('Please enter the gender of your character (m/f)')
#doCreateCharacterSex.prompt = 'Is your character a male or female (m/f)'

def doCreateCharacterPassion(self, session):
    "Choose Passion"
    if self.cmd:
	if self.cmd in ["Chorrolis", "Dis", "Floranuus", "Garlen", "Jaspree", "Lochost", \
		    "Mynbruje", "Raggok", "Thystonius", "Upandal", "Vestrial", "none"]:
	    #self.insertStatement = self.insertStatement + '%s\',\'' % (self.cmd)
	    self.passion = self.cmd
	    return True
	    #self.setState(self.doCreateCharacterDiscipline)
	else:
	    session.push('Please enter the Passion your character worships.  Your choices are\nChorrolis \
			       \nDis\nFloranuus\nGarlen\nJaspree\nLochost\nMynbruje\nRaggok\nThystonius \
			       \nUpandal\nVestrial\nnone\n(you can change this later if your unsure)')
    else:
	session.push('Please enter the Passion your character worships.  Your choices are\nChorrolis \
			       \nDis\nFloranuus\nGarlen\nJaspree\nLochost\nMynbruje\nRaggok\nThystonius \
			       \nUpandal\nVestrial\nnone\n(you can change this later if your unsure)')
#doCreateCharacterPassion.prompt = 'Please enter the Passion your character worships.  Your choices are\nChorrolis \
			       #\nDis\nFloranuus\nGarlen\nJaspree\nLochost\nMynbruje\nRaggok\nThystonius \
			       #\nUpandal\nVestrial\nnone\n(you can change this later if your unsure)'


def doCreateCharacterDiscipline(self, session):
    "Select character discipline for the game"
    if self.cmd:
	if self.cmd in ["air sailor", "archer", "beastmaster", "cavalryman", "elementalist", "illusionist", \
		    "nethermancer", "scout", "sky raider", "swordmaster", "thief", "troubadour", \
		    "warrior", "weaponsmith", "wizard"]:
	    #self.insertStatement = self.insertStatement + '%s\',\'' % (self.cmd)
	    self.discipline = self.cmd
	    # set up minimums/maximums
	    #'obsidiman': {'s':(9,18)},
	    #'troll': {'s':(7,18), 't':(9,18)},
	    #'windling': {'s':(2,15)}
	    #if self.race in ["obsidiman", "troll", "windling"]:
	    if self.race == 'dwarf':
		stats['c'] = 3
		stats['points'] -= 1
	    elif self.race == 'elf':
		stats['t'] = 4
		stats['points'] -= 5
	    elif self.race == 'obsidiman':
		stats['d'] = 4
		stats['p'] = 3
		stats['c'] = 3
		stats['s'] = 9
		stats['points'] -= 11
	    elif self.race == 'troll':
		stats['p'] = 3
		stats['s'] = 7
		stats['t'] = 9
		stats['points'] -= 5
	    else: # must be 'windling':
		stats['s'] = 6
		stats['t'] = 5
		stats['points'] -= 13
		
	    
	    session.push('Now your character attributes must be created.  The following table will assist you\n \
				Attribute   Purchase    Attribute   Purchase\n \
				Value       Points      Value       Points\n \
				   2           +3          11          6\n \
				   3           +2          12          8\n \
				   4           +1          13         10\n \
				   5            0          14         13\n \
				   6            1          15         16\n \
				   7            2          16         19\n \
				   8            3          17         21\n \
				   9            4          18         23\n \
				  10            5\
				\nSetting all values to the minimum for your race, you now have \
				\nDexterity:  %i (%i)   Strength:  %i (%i)  Toughness: %i (%i)\
				\nPerception: %i (%i)   Willpower: %i (%i)  Charisma:  %i (%i)\
				\nYou have %i points left to spend. \
				\nSet attribute total using "s X" where s is the first letter  \
				\nof the attribute and X is the new value. \
				\nExample: c 15 would set charisma at 15 and cost you 16 purchase points \
				\nNote: if you lower a score - purchase points are "recovered" \
				\nNumbers in parentheses () are the attributes modified for your race \
				\nPlease enter an attribute modification (s 15), "table", or "done"\n' \
				% (stats['d'], (stats['d']+ self.statMod['d']), stats['s'], \
				    (stats['s']+ self.statMod['s']), stats['t'], (stats['t']+ self.statMod['t']), \
				    stats['p'],(stats['p']+ self.statMod['p']), stats['w'],\
				    (stats['w']+ self.statMod['w']), stats['c'],(stats['c']+ self.statMod['c']), \
				    stats['points']))
	    #self.setState(self.doCreateCharacterStats)
	    #doCreateCharacterStats(self,session)
	    return True
	else:
	    session.push('Please enter your character\'s discipline.  Your choices are\n \
			   air sailor\narcher\nbeastmaster\ncavalryman\nelementalist\n \
			   illusionist\nnethermancer\nscout\nsky raider\nswordmaster\n \
			   thief\ntroubadour\nwarrior\nweaponsmith\nwizard\n')
#doCreateCharacterDiscipline.prompt = 'Please enter your character\'s discipline.  Your choices are \
				     #\nair sailor\narcher\nbeastmaster\ncavalryman\nelementalist \
				     #\nillusionist\nnethermancer\nscout\nsky raider\nswordmaster \
				     #\nthief\ntroubadour\nwarrior\nweaponsmith\nwizard'

def doCreateCharacterStats(self, session):
    "Create a new character name for the game"
    if self.cmd:
	if self.cmd == 'table':
	    session.push('Attribute   Purchase    Attribute   Purchase \
			    \nValue       Points      Value       Points \
			    \n   2           +3          11          6 \
			    \n   3           +2          12          8 \
			    \n   4           +1          13         10 \
			    \n   5            0          14         13 \
			    \n   6            1          15         16 \
			    \n   7            2          16         19 \
			    \n   8            3          17         21 \
			    \n   9            4          18         23 \
			    \n  10            5 \
			    \n\nYou now have \
			    \nDexterity:  %i (%i)   Strength:  %i (%i)   Toughness: %i (%i)\
			    \nPerception: %i (%i)   Willpower: %i (%i)   Charisma:  %i (%i)\
			    \nYou have %i points left to spend \
			    \nPlease enter an attribute modification (s 15), "table", or "done"\n'\
			    % (stats['d'], (stats['d']+ self.statMod['d']), stats['s'], \
				    (stats['s']+ self.statMod['s']), stats['t'], (stats['t']+ self.statMod['t']), \
				    stats['p'],(stats['p']+ self.statMod['p']), stats['w'],\
				    (stats['w']+ self.statMod['w']), stats['c'],(stats['c']+ self.statMod['c']), \
				    stats['points']))
	elif self.cmd == 'done':
	    
	    # modified for race here

	    if self.race == 'dwarf':
		stats['s'] += 2
		stats['t'] += 3
		stats['c'] -= 1
	    
	    elif self.race == 'elf':
		stats['d'] += 2
		stats['t'] -= 2
		stats['p'] += 1
		stats['w'] += 1
		stats['c'] += 1
		
	    elif self.race == 'human':
		pass
	    
	    elif self.race == 'obsidiman':
		stats['d'] -= 2
		stats['s'] += 6
		stats['t'] += 4
		stats['p'] -= 1
		stats['c'] -= 1
	    
	    elif self.race == 'ork':
		stats['d'] -= 1
		stats['s'] += 3
		stats['t'] += 1
		stats['w'] -= 1
		stats['c'] -= 1
		
	    elif self.race == 'troll':
		stats['s'] += 4
		stats['t'] += 2
		stats['p'] -= 1
		stats['w'] += 1
	    
	    elif self.race == 't\'skrang':
		stats['d'] += 1
		stats['t'] += 1
		stats['c'] += 1
		
	    elif self.race == 'windling':
		stats['d'] += 1
		stats['s'] -= 4
		stats['t'] -= 3
		stats['p'] += 1
		stats['c'] += 2         

	    #self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
		#		% (self.stats['d'], self.stats['s'], self.stats['t'], self.stats['p'], self.stats['w'], self.stats['c'])
	    self.dexterity = stats['d']
	    self.strength = stats['s']
	    self.toughness = stats['t']
	    self.perception = stats['p']
	    self.willpower = stats['w']
	    self.charisma = stats['c']
	    # are now able to set attribute dependent traits
	    doCreateCharacterAttributeDependendentTraits(self)
	    return True
	    
	    #self.setState(self.doCreateCharacterDescription)
	elif self.cmd[0] in ["d", "s", "t", "p", "w", "c"]:
	    try:
		if int(self.cmd[2:]) in range(2,19):
		    # a flag to make sure min max rules apply
		    ok = 1
		    
		    # need to check min and max stats for race
		    if self.race in ["obsidiman", "troll", "windling"]:
			if self.race == 'obsidiman':
			    if self.cmd[0] == 's':
				if int(self.cmd[2:]) < 9:
				    session.push('Sorry, that would be below the minimum strength for an obsidiman.\n')
				    ok = 0
			elif self.race == 'troll':
			    if self.cmd[0] == 's':
				if int(self.cmd[2:]) < 7:
				    session.push('Sorry, that would be below the minimum strength for a troll.\n')
				    ok = 0
			    if self.cmd[0] == 't':
				if int(self.cmd[2:]) < 9:
				    session.push('Sorry, that would be below the minimum toughness for a troll.\n')
				    ok = 0
			else: # must be 'windling':
			    if self.cmd[0] == 's':
				if self.cmd[2:] > 15:
				    session.push('Sorry, that would be above the maximum strength for a windling.\n')
				    ok = 0
		    if ok == 1:
			#calculate the number of points it will cost
			#these next 2 lines shoudn't be this complicated...must be missing something
			expression = compile("pointCost['" + self.cmd[2:] + "']", '', 'eval')
			pointModifier = eval(expression)
			#check to see if they have enough points left
			#if self.stats['points'] + pointModifier >= 0:
			
			#first add back old value
			expression = compile("stats['" + self.cmd[0] + "']", '', 'eval')
			oldValue = eval(expression)
			expression = compile("pointCost['" + str(oldValue) + "']", '', 'eval')
			oldpointModifier = eval(expression)
			pointModifier = pointModifier + -(oldpointModifier)
			if stats['points'] + pointModifier >= 0:
			    #update attribute
			    stats[self.cmd[0]] = int(self.cmd[2:])
			    #remove points
			    stats['points'] = stats['points'] + pointModifier
			    session.push('Attribute altered. (enter "table" for status)\n')
			else:
			    session.push('Not enough points to do that! (enter "table" for status)\n')
		else:
		    session.push('Invalid attribute assignment - minimum 2 and maximum 18. Please try again.\n')
	    except:
		session.push('Invalid attribute assignment. Please try again.\n')

    else:
	session.push('Please enter an attribute modification (s = 15), "table", or "done"\n')

#doCreateCharacterStats.prompt = ''

def doCreateCharacterAttributeDependendentTraits(self):
    defenseRating = [0,2,3,3,4,4,4,5,5,6,6,7,7,7,8,8,9,9,10,10,10,11,11,12,12,13,13,13,14,14,15]
    initiativeRating = [0,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11]
    #movementFull = [0,25,28,30,32,35,38,40,43,48,50,54,57,60,65,70,75,80,85,90,100,110,120,130,140,150,160,170,180,200,220]
    #movementCombat = [0,13,14,15,16,18,19,20,22,24,25,27,29,30,33,35,38,40,43,45,50,55,60,65,70,75,80,80,85,90,100,110]
#    maxCarry = [0,10,15,20,25,30,35,40,50,60,70,80,90,105,125,145,165,200,230,270,315,360,430,500,580,675,790,920,1075,1200,1450]  
    maxCarry = [0, 5,10,15,20,25,30,40,50,60,70,80,95,110,125,140,160,180,200,230,260,290,330,370,410,510,560,620,680,740]
#    maxLift = [0,20,30,40,50,65,75,85,100,115,135,160,185,210,250,290,310,400,460,540,630,735,860,1000,1160,1350,1580,1840,2150,2500,2900]
    maxLift = [0, 10,20,30,40,50,60,80,100,120,140,160,190,220,250,280,320,400,460,520,580,660,740,820,920,1020,1120,1240,1360,1480]
    deathRating = [0,19,20,22,23,24,26,27,28,30,31,32,34,35,36,38,39,40,42,43,44,46,47,48,50,51,52,54,55,56,58]
    woundThreshold = [0,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,13,14,14,15,15,15,16,16,17]
    unconsciousRating = [0,10,11,13,14,15,17,18,19,21,22,24,26,27,28,29,31,32,34,35,36,39,40,41,43,44,45,47,48,49,51]
    recoveryTests = [0,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5]
    mysticArmor = [0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7]
    karma = {'dwarf':(4, 6, 25), 'elf':(4, 6, 25), 'human':(5, 10, 40),
	'obsidiman':(3, 5, 20), 'ork':(5, 10, 40), 'troll':(4, 6, 20),
	't\'skrang':(4, 6, 25), 'windling':(6, 15, 60)}

   
    #self.data = (pname, self.email, self.truepass, self.salty, 0, self.description, self.ansi, self.discipline, self.circle, \
		 #self.race, self.gender, self.age, self.spouse_name, self.dexterity, self.strength, self.toughness, self.perception, \
		 #self.willpower, self.charisma, self.initiative, self.fly, self.max_carry, self.max_lift, self.physical_defense, \
		 #self.spell_defense, self.social_defense, self.normal_armor, self.mystical_armor, self.wound_threshold, self.damage, \
		 #self.wound, self.unconscious_rating, self.death_rating, self.blood_magic_cost, self.recovery_tests_left, \
		 #self.recovery_test_total, self.karma_dice, self.karma_current, self.karma_max, self.legend_unspent, self.legend_total, \
		 #self.passion)    
    
    
    self.max_carry = maxCarry[stats['s']]
    self.max_lift = maxLift[stats['s']]
    self.physical_defense = defenseRating[stats['d']]
    self.spell_defense = defenseRating[stats['p']]
    self.social_defense = defenseRating[stats['c']]
    self.normal_armor = 0
    self.mystical_armor = mysticArmor[stats['w']]
    self.wound_threshold = woundThreshold[stats['t']]
    self.damage = 0
    self.wound = 0
    self.unconscious_rating = unconsciousRating[stats['t']]
    self.death_rating = deathRating[stats['t']]
    self.blood_magic_cost = 0
    self.recovery_tests_left = recoveryTests[stats['t']]
    self.recovery_tests_total = recoveryTests[stats['t']]
    self.karma_dice = karma[self.race][0]
    self.karma_current = karma[self.race][1]
    self.karma_max = karma[self.race][2]
    self.legend_unspent = 0
    self.legend_total = 0
    self.circle = 0
    self.spouse_name = ''
    self.initiative = initiativeRating[stats['d']]
    self.fly = 0
    if self.race == "obsidiman": # increased wound threshold and increased physical armor
	self.wound_threshold = woundThreshold[stats['t']]+3
	self.normal_armor = 3
	normAge = 100
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1))) # goofy little random age function
    elif self.race == "windling": # increased physical defense and flight
	self.physical_defense = defenseRating[stats['d']]+2
	self.fly = 1
	normAge = 30
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "dwarf": # increased physical defense and flight
	normAge = 10
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "elf": # increased physical defense and flight
	normAge = 20
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "human": # increased physical defense and flight
	normAge = 16
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "ork": # increased physical defense and flight
	normAge = 14
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "troll": # increased physical defense and flight
	normAge = 14
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
    elif self.race == "t'skrang": # increased physical defense and flight
	normAge = 30
	self.age = normAge + randrange(int(-.1 * normAge),int(.1 * (normAge + 1)))
	
	
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##    % (defenseRating[self.stats['d']], defenseRating[self.stats['p']], defenseRating[self.stats['c']], \
	##       maxCarry[self.stats['s']], \
	##       maxLift[self.stats['s']], deathRating[self.stats['t']], woundThreshold[self.stats['t']]+3, \
	##       unconsciousRating[self.stats['t']], recoveryTests[self.stats['t']], mysticArmor[self.stats['w']])
	    
    #elif race == "windling": # increased physical defense

	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##    % (defenseRating[self.stats['d']]+2, defenseRating[self.stats['p']], defenseRating[self.stats['c']], \
	##       maxCarry[self.stats['s']], \
	##       maxLift[self.stats['s']], deathRating[self.stats['t']], woundThreshold[self.stats['t']], \
	##       unconsciousRating[self.stats['t']], recoveryTests[self.stats['t']], mysticArmor[self.stats['w']]) 

    #else:                                        
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##    % (defenseRating[self.stats['d']], defenseRating[self.stats['p']], defenseRating[self.stats['c']], \
	##       maxCarry[self.stats['s']], \
	##       maxLift[self.stats['s']], deathRating[self.stats['t']], woundThreshold[self.stats['t']], \
	##       unconsciousRating[self.stats['t']], recoveryTests[self.stats['t']], mysticArmor[self.stats['w']])    
    
    ## now do movementFull, movementCombat, flyingcombat, flyingnormal based off of race
    ## also do karmadice, karmacost, karmacurrent, karmamax
    #if self.race == 'dwarf':
	#if self.stats['d'] < 5:
	    #self.stats['d'] = 5
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']-2], movementCombat[self.stats['d']-2], \
	##   0, 0, karma['dwarf'][0], karma['dwarf'][1], karma['dwarf'][2], karma['dwarf'][3])
    
    #elif self.race == 'elf':
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']+1], movementCombat[self.stats['d']+1], \
	##   0, 0, karma['elf'][0], karma['elf'][1], karma['elf'][2], karma['elf'][3])
	
    #elif self.race == 'human':
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']], movementCombat[self.stats['d']], \
	##   0, 0, karma['human'][0], karma['human'][1], karma['human'][2], karma['human'][3])
    
    #elif self.race == 'obsidiman':
	#if self.stats['d'] < 6:
	    #self.stats['d'] = 6
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']-3], movementCombat[self.stats['d']-3], \
	##   0, 0, karma['obsidiman'][0], karma['obsidiman'][1], karma['obsidiman'][2], karma['obsidiman'][3])
    
    #elif self.race == 'ork':
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']+1], movementCombat[self.stats['d']+1], \
	##   0, 0, karma['ork'][0], karma['ork'][1], karma['ork'][2], karma['ork'][3])
	
    #elif self.race == 'troll':
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']+2], movementCombat[self.stats['d']+2], \
	##   0, 0, karma['troll'][0], karma['troll'][1], karma['troll'][2], karma['troll'][3])
    
    #elif self.race == 't\'skrang':
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[self.stats['d']], movementCombat[self.stats['d']], \
	##   0, 0, karma['t\'skrang'][0], karma['t\'skrang'][1], karma['t\'skrang'][2], karma['t\'skrang'][3])
	
    #elif self.race == 'windling':
	#modDex = 0
	#if self.stats['d'] < 11:
	    #modDex = 11
	#else:
	    #modDex = self.stats['d']    
	##self.insertStatement = self.insertStatement + '%i\',\'%i\',\'%i\',\'%i\',\'' \
	##% (movementFull[modDex], movementCombat[modDex], \
	##    movementFull[self.stats['d']+2], movementCombat[self.stats['d']+2],
	##    karma['windling'][0], karma['windling'][1], karma['windling'][2], karma['windling'][3])
	
   
    ## insert inititive - will just put step in here now
    ##self.insertStatement = self.insertStatement + '%i\',\'' % (self.stats['d'])
    
    ## insert recovery dice - will just put step in here for now
    ##self.insertStatement = self.insertStatement + '%i\',\'' % (self.stats['t'])
    
    ## insert NOW into datelaston
    ##self.insertStatement = self.insertStatement + '%s\',\'' % (time.ctime())
    
    ## go ahead an insert all default values here
    ## spousename,age,circle, normalarmor, damage, wound, bloodmagic, legendunspent, legendtotal, money, isbot, roomid
    
    ##need to increase the physical armor of obsidimen
    #if self.race == 'obsidiman':
	##self.insertStatement = self.insertStatement + '%s\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\', \
	##		   \'%i\',\'%i\',\'%i\',\'' % ('none', 20, 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1)
    
    #else:
	##self.insertStatement = self.insertStatement + '%s\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\',\'%i\', \
	##		   \'%i\',\'%i\',\'%i\',\'' % ('none', 20, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1) 


def doCreateCharacterDescription(self, session):
    "Create a new character ddscription"
    if self.cmd:
	#self.insertStatement = self.insertStatement + "%s\')" % (string.replace(self.cmd,"'","\\'"))
	naughty = False
	badnames = open('badnames', 'r')
	for naughtyword in badnames:
	    if naughtyword.strip() in self.cmd:
		naughty = True
		break
	badnames.close()	
	
	if (naughty):
	    session.push('Your description must not contain profanity.\n')
	    return false
	else:
	    self.description = self.cmd
	    session.push('Ready to save character.  Press <enter> to continue.\n')
	    return True
	
	#try:
	    ##db = MySQLdb.connect("localhost", "code", "Oicu812@2", "earthdawndb")
	    ##cursor = db.cursor()
	  
	    ##gv.cursor.execute(self.insertStatement)
	    ##result = gv.cursor.rowcount
	    #try:
		#if result >= 1:
		    #self.doloadPlayer(self.user)
		#else: #username and password don't match
		    #self.setState = self.doInvalid
	    #except: #didn't get anything from DB - username doesn't exist
		#self.doInvalid(self.cmd)
	#except: #DB not running
	    #self.doInvalid(self.cmd)
	##self.doloadPlayer(self.user)
    else:
	session.push('Please enter a description for your character')
#doCreateCharacterDescription.prompt = 'Please enter a description for your character'
    

### @package command
##  Accepts, parses, and dispatches commands according to context.
##
##  Accepted typed input is queued as (speaker, message) tuples within command_queue.
##  The first word within the message constitutes the command, which is mapped
##  according to the instructions within config/handlers-map.xml and the handlers
##  system constructed by handler.py.  Dispatched commands are mapped to handler
##  definitions within the handlers/ directory.

#import libsigma, time
##from eris import sessions

#command_queue = []

### Enqueues a raw message to command_queue for later processing.
##  @param speaker The character initiating the message.
##  @param message The typed (or simulated-typed input).
#def accept_command(start, speaker, message):
	#command_queue.append((start, speaker, message))

### Parses a raw message into a command and argument list.
##
##  If a command is successfully mapped to a handler, the handler function
##  is executed using libsigma's safe_mode mechanism, to trap and report
##  errors on the console rather than halting execution (since all handlers
##  are optional).
##  
##  run_command is only executed when the character is in STATE_PLAYING.
##  Input within other states is handled by process_commands.
##  
##  @param speaker The character initiating the message.
##  @param message The typed (or simulated-typed input).
##  
##  @sa For more information, please see libsigma.safe_mode and handler.py.
#def run_command(speaker, message):
	#reduced = message.lstrip()
	#if reduced:
		#if reduced[0] == "'" and handler.specials["apostrophe"]:
			#message = handler.specials["apostrophe"] + " " + reduced[1:]
		#elif reduced[0] == ',' and handler.specials["comma"]:
			#message = handler.specials["comma"] + " " + reduced[1:]
		#elif reduced[0] == ':' and handler.specials["colon"]:
			#message = handler.specials["colon"] + " " + reduced[1:]
		#elif reduced[0] == '.' and handler.specials["period"]:
			#message = handler.specials["period"] + " " + reduced[1:]
	#else:
		#return True

	#try:
		#tokens = message.lower().split()
	#except:
		#return False

	#tail = message[(message.find(tokens[0]) + len(tokens[0])):].lstrip()

	#if len(tokens):
		#for (command, function) in handler.mappings:
			#if command.startswith(tokens[0]):
				#libsigma.safe_mode(function, {
					#"speaker" : speaker,
					#"args" : tokens,
					#"message" : message,
					#"tail" : tail,
					#"mapped" : command
					#})
				#return True
		#return False
	#else:
		#return True

### Flush the command queue and respond to all user input.
##def process_commands(sessions, Actions):
	##while len(command_queue) > 0:
		###test = len(sessions)
		##command_queue.sort(lambda x,y:cmp(x[0],y[0]))
		##start = command_queue[-1][0]
		##if start <= time.time():
			###start, speaker, message = command_queue.pop(-1)
			##start, message = command_queue.pop(-1)
			##prompt = True
			
			##Actions.do_kill(sessions, 'bob')
			
			###if not run_command(speaker, message):
				###speaker.send_line("What?")

			
			
			
			
	##while len(command_queue) > 0:
		##speaker, message = command_queue.pop(0)
		##prompt = True

		##if not run_command(speaker, message):
			##speaker.send_line("What?")

		##if speaker.socket and prompt:
			##speaker.send_prompt()
